package org.cypress.rtpack.common.exception;

import lombok.Data;

/**
 * 已明确知道的异常，需要告知用户的，比如用户操作不当引起的异常，此类异常的描述需要支持国际化
 */
@Data
public class BizException extends RuntimeException {

	private int code;

	private String desc;

	public BizException(Exception ex) {
		this(ExceptionCode.fail, ex);
	}

	/**
	 * 对已有异常封装，方便输出堆栈信息，用于日志
	 *
	 * @param code
	 * @param ex
	 */
	public BizException(ExceptionCode code, Exception ex) {
		super(code.getCode() + "-" + code.getDesc(), ex);
		this.code = code.getCode();
	}

	/**
	 * 需要展示给前端的异常
	 *
	 * @param code
	 */
	public BizException(ExceptionCode code) {
		super(code.getCode() + "-" + code.getDesc());
		this.code = code.getCode();
		this.desc = code.getDesc();
	}

	public BizException(ExceptionCode code, String message) {
		super(code.getCode() + "-" + message);
		this.code = code.getCode();
		this.desc = message;
	}

	public BizException(ExceptionCode code, String message, Exception ex) {
		super(code.getCode() + "-" + code.getDesc(), ex);
		this.code = code.getCode();
		this.desc = message;
	}
}
